package com.cantuaria.jsf.util;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/*
 * @Autor: Flávio CANTUÁRIA
 */


public class HibernateUtil extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
	private static SessionFactory sessionFactory;
    private static Logger log = Logger.getLogger(HibernateUtil.class);
	
    @Override
    public void init() throws ServletException {
	    try {
	    	sessionFactory = new Configuration().configure().buildSessionFactory();
	   } catch (Throwable ex) {
		   log.error("Não foi criado o factory do hibernate");
		   throw new ExceptionInInitializerError(ex);
	   }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    
}
